package com.zoro.dyformservice.support.jpa.converters;

import com.zoro.dyformservice.constants.response.common.Sex;
import jakarta.persistence.AttributeConverter;
import jakarta.persistence.Converter;

@Converter(autoApply = true)
public class SexConverter implements AttributeConverter<Sex, String> {


    @Override
    public String convertToDatabaseColumn(Sex attribute) {
        if (attribute == null) {
            return null;
        }
        return attribute.code;
    }

    @Override
    public Sex convertToEntityAttribute(String dbData) {
        return Sex.getByCode(dbData);
    }
}
